<template>
  <el-dialog v-model="dialogVisible" :before-close="handleClose">
    <div class="title">派发任务</div>
    <el-form ref="menuRef" :model="form" :rules="rules" label-width="auto" label-position="top">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="执行部门" prop="processingUnit">


            <el-select v-model="form.processingUnit" placeholder="请选择执行部门" size="large">
              <el-option
                v-for="item in [
                  { label: '部门一', value: '部门一' },
                  { label: '部门二', value: '部门二', },
                  { label: '部门三', value: '部门三' },
                  { label: '部门四', value: '部门四' },
                  { label: '部门五', value: '部门五' },
                  { label: '部门六', value: '部门六' },
                ]"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="任务描述">
            <el-input
              type="textarea"
              :maxlength="200"
              v-model.trim="form.taskDescription"
              show-word-limit
              placeholder="请输入任务描述"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="loading">
          <template #loading>
            <div class="custom-loading">
              <svg class="circular" viewBox="-10, -10, 50, 50">
                <path
                  class="path"
                  d="
            M 30 15
            L 28 17
            M 25.61 25.61
            A 15 15, 0, 0, 1, 15 30
            A 15 15, 0, 1, 1, 27.99 7.5
            L 15 15
          "
                  style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"
                />
              </svg>
            </div>
          </template>
          提交</el-button
        >
        <el-button @click="handleClose">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { onBeforeMount, onMounted, reactive, ref, toRefs } from 'vue'
import { addDispatchAPI } from '@/api/home.js'
import _ from 'lodash'
const { proxy } = getCurrentInstance()
const form = ref<any>({})
const emits = defineEmits(['submitFun'])
const dialogVisible = ref(false)
const rules = ref({
  processingUnit: [{ required: true, message: '请输入执行部门', trigger: 'blur' }],
  taskDescription: [{ required: true, message: '请输入任务描述', trigger: 'blur' }],
})
const loading = ref(false)
const handleClose = () => {
  console.log(123123)
  dialogVisible.value = false
  proxy.$refs['menuRef'].resetFields()
  form.value = {}
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs['menuRef'].validate((valid) => {
    if (valid) {
      loading.value = true
      addDispatchAPI({ ...form.value, status: 2 }).then((response) => {
        loading.value = false
        handleClose()
        emits('submitFun')
      })
    }
  })
}
const open = (data) => {
  form.value = _.cloneDeep(data)
  dialogVisible.value = true
}
const state = reactive({})
onBeforeMount(() => {})
onMounted(() => {})
defineExpose({ open })
defineOptions({
  name: 'rulebase',
})
</script>
<style lang="scss" scoped>
.custom-loading {
  .circular {
    margin-right: 6px;
    width: 18px;
    height: 18px;
    animation: loading-rotate 2s linear infinite;
    .path {
      animation: loading-dash 1.5s ease-in-out infinite;
      stroke-dasharray: 90, 150;
      stroke-dashoffset: 0;
      stroke-width: 2;
      stroke: var(--el-button-text-color);
      stroke-linecap: round;
    }
  }
}
.title {
  font-size: 18px;
  text-align: center;
  font-weight: 600;
  margin-bottom: 20px;
}
</style>
